#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>

#include<vector>

#include<stack>
#include<string>

using namespace std;

#define int long long


signed main()
{
	bool flag = false;
	stack<string> stk;
	string s;
	if (s == "not" || s == "and" || s == "or")
	{
		cout << "error" << endl;
		return 0;
	}
	vector<pair<string, int>>str;
	string pre;
	getline(cin, s);
	int cnt = 0;
	int j = 0;
	int la = 0;
	for (j = 0, la = 0; j < s.size(); j++)
	{
		if (s[j] == ' ')
		{
			string t = s.substr(la, j - la);
			int x;
			if (t == "true")
				x = 1;
			else if (t == "false")
				x = 0;
			else x = 2;
			str.push_back(make_pair(t, x));
			la = j + 1;
			j++;
			cnt++;
			//cout << t << ' ' << x << endl;
		}
	}


	string t = s.substr(la);
	int x;
	if (t == "true")
		x = 1;
	else if (t == "false")
		x = 0;
	else x = 2;
	str.push_back(make_pair(t, x));
	// for(int i = 0;i < str.size();i ++)
	// 	cout << str[i].first << ' ' << str[i].second;


	if (str.size() == 1)
	{
		if (str[0].first == "not")
		{
			cout << "error" << endl;
			return 0;
		}
		else if(str[0].first == "true")
		{
			cout << "true" << endl;
			return 0;
		}
		else
		{
			cout << "false" << endl;
			return 0;
		}
	}
	else if (str.size() == 2)
	{
		if (str[0].first == "true")
		{
			if (str[1].first == "false")
			{
				cout << "error" << endl;
				return 0;
			}
		}
		else if (str[1].first == "true")
		{
			if (str[0].first == "false")
			{
				cout << "error" << endl;
				return 0;
			}
		}

		if (str.back().first == "not")
		{
			cout << "error" << endl;
			return 0;
		}
	}

	

	for (int i = 1; i < str.size() - 1; i++)
	{
		if (str[i].first == "and" || str[i].first == "or")
		{
			if (str[i - 1].first == "and" || str[i - 1].first == "or" || str[i + 1].first == "and" || str[i + 1].first == "or")
			{
				cout << "error" << endl;
				return 0;
			}
		}
		if (str[i].first == str[i - 1].first || str[i].first == str[i + 1].first)
		{
			cout << "error" << endl;
			return 0;
		}
	}

	vector<pair<string,int>> vstr;
	int cur = 0;
	while(cur < str.size())
	{
		if (cur < str.size() &&str[cur].first != "not")
		{
			vstr.push_back(str[cur++]);
		}

		if (cur < str.size() && str[cur].first == "not")
		{
			if (str[cur + 1].first == "and" || str[cur + 1].first == "or")
			{
				cout << "error" << endl;
				return 0;
			}

			if (cur + 1 < str.size() && str[cur + 1].first == "true")
			{
				vstr.push_back(make_pair("false",0));
				cur+=2;
			}
			else if(cur + 1 < str.size() && str[cur + 1].first == "false")
			{
				vstr.push_back(make_pair("true", 0));
				cur+=2;
			}
		}
	}

	if (vstr.size() == 1)
	{
		cout << vstr[0].first << endl;
		return 0;
	}
	vector<string> v1;

	for (auto& x : vstr)
	{
		x.second = 0;
	}

	for (int i = 1; i < vstr.size() - 1; i++)
	{
		if (vstr[i].first == "and")
		{
			if (vstr[i - 1].second == 0)
			{
				v1.push_back(vstr[i - 1].first);
				vstr[i - 1].second = 1;
			}

			if (vstr[i + 1].second == 0)
			{
				v1.push_back(vstr[i + 1].first);
				vstr[i + 1].second = 1;
			}

			v1.push_back(vstr[i].first);
		}
	}

	for (int i = 1; i < vstr.size() - 1; i++)
	{
		if (vstr[i].first == "or")
		{
			if (vstr[i - 1].second == 0)
			{
				v1.push_back(vstr[i - 1].first);
				vstr[i - 1].second = 1;
			}

			if (vstr[i + 1].second == 0)
			{
				v1.push_back(vstr[i + 1].first);
				vstr[i + 1].second = 1;
			}

			v1.push_back(vstr[i].first);
		}
	}

	if (v1.size() == 1)
	{
		cout << v1[0] << endl;
		return 0;
	}

	for (auto x : v1)
	{
		if (x != "and" && x != "or" && x != "not")
		{
			stk.push(x);
		}

		if (x == "and")
		{
			string a, b;
			a = stk.top();
			stk.pop();

			b = stk.top();
			stk.pop();

			if (a == "false" || b == "false")
			{
				stk.push("false");
			}
			else
			{
				stk.push("true");
			}
		}
		else if (x == "or")
		{
			string a, b;
			a = stk.top();
			stk.pop();

			b = stk.top();
			stk.pop();

			if (a == "true" || b == "true")
			{
				stk.push("true");
			}
			else
			{
				stk.push("false");
			}
		}
	}
	for (int i = 0; i < vstr.size(); i++)
	{
		cout << vstr[i].first << ' ';
		
	}
	if (stk.top() == "true")
	{
		cout << "true" << endl;
	}
	else
	{
		cout << "false" << endl;
	}
	return 0;
}